﻿using UnityEngine;
using System.Collections;

public class UpdateZ : MonoBehaviour {

    public float yOffset;
    Vector3 pos;


    void Start()
    {
        pos = transform.localPosition;
    }

	// Update is called once per frame
	void Update () {
        pos.z = ((transform.position.y + yOffset) - Camera.main.transform.position.y) / Camera.main.orthographicSize - 2;
        transform.localPosition = pos;
	}

    void OnDrawGizmos()
    {
        Gizmos.DrawLine(transform.position, transform.position + new Vector3(0, yOffset));
    }
}
